--许以秘密
local xuyimimi = fk.CreateSkill {
    name = "mcdh_xuyimimi",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

xuyimimi:addEffect('active',{
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self,player, to_select, selected)
        return #selected == 0 and to_select ~= player and not to_select:isKongcheng()
    end,
    target_num = 1,
    on_use = function(self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        local id = room:askForCardChosen(player, target, "h", self.name)
        room:obtainCard(effect.from, id, false)
        local mark = player:getTableMark("#mcdh_xuyimimi-turn")
        table.insertIfNeed(mark,target.id)
        room:setPlayerMark(player,"#mcdh_xuyimimi-turn",mark)
    end,
})

xuyimimi:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        if target == player and player.phase == Player.Finish and not player:isKongcheng() then
            local room = player.room
            local targets = player:getTableMark("#mcdh_xuyimimi-turn")
            for _, tid in ipairs(targets) do
                local to = room:getPlayerById(tid)
                if to.dead then
                    table.removeOne(targets,tid)
                end
            end
            room:setPlayerMark(player,"#mcdh_xuyimimi-turn",targets)
            return #player:getTableMark("#mcdh_xuyimimi-turn") ~= 0
        end
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local suits = {"log_spade", "log_club", "log_heart", "log_diamond"}
        local mark = player:getTableMark("#mcdh_xuyimimi-turn")
        for _, tid in ipairs(mark) do
            if player:isKongcheng() then
                break
            end
            local to = room:getPlayerById(tid)
            local choice = room:askForChoice(to, suits, self.name,"#mcdh_xuyimimi_trigger-prompt::"..player.id)
            local card = room:askForCardChosen(to, player, "h", self.name)
            to:showCards(card)
            if Fk:getCardById(card):getSuitString(true) == choice then
                local targets = room:getAlivePlayers(true)
                local to =room:askToChoosePlayers(to, {
                      targets = targets,
                      min_num = 1,
                      max_num = 1,
                      prompt = "#mcdh_xuyimimi_trigger-choose",
                      skill_name = self.name,
                      cancelable = false
                    })[1]
                room:damage{
                    from = to,
                    to = to,
                    damage = 1,
                    skillName = self.name,
                }
            end
        end
    end,
})

Fk:loadTranslationTable {
    ["mcdh_xuyimimi"] = "许以秘密",
    [":mcdh_xuyimimi"] = "『许以秘密』<br>出牌阶段限一次，你可以获得一名其他角色的一张手牌。若如此做，结束阶段，其声明一种花色并展示你的一张手牌，若展示牌与其声明的花色相同，其对一名角色造成1点伤害。",
    ["#mcdh_xuyimimi_trigger"] = "许以秘密",
    ["#mcdh_xuyimimi_trigger-choose"] = "许以秘密：对一名角色造成1点伤害",
    ["#mcdh_xuyimimi_trigger-prompt"] = "许以秘密：声明一种花色并展示 %dest 的一张手牌，若展示牌与声明的花色相同，你对一名角色造成1点伤害。",
}

return xuyimimi